<template>
  <el-form :model="ruleForm" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="菜品名称" prop="cname">
      <el-input v-model="ruleForm.cname"></el-input>
    </el-form-item>
    <el-form-item label="菜品描述" prop="cdesc">
      <el-input v-model="ruleForm.cdesc"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  import axios from "axios";
  export default {
    name: "CategoryAdd",
    data() {
      return {
        ruleForm: {
          cname: '',
          cdesc: '',
        },
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            axios.post("/api/saveCategory",this.ruleForm).then(res=>{
              if (res.data=="success"){
                this.$router.push("/categoryList")
              }else{
                alert("修改失败")
              }
            })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
    },

  }
</script>

<style scoped>

</style>
